//
//  CollectViewController.m
//  CarHome
//
//  Created by lanou3g on 15-5-3.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "CollectViewController.h"
#import "XHMenu.h"
#import "XHScrollMenu.h"

#import "SystemTableViewController.h"
#import "ModelTableViewController.h"


@interface CollectViewController () <XHScrollMenuDelegate,UIScrollViewDelegate, UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) XHScrollMenu *scrollMenus;
@property (nonatomic, retain) NSMutableArray *menus;
@property (nonatomic, assign) BOOL shouldObserving;
@end



@implementation CollectViewController
- (NSMutableArray *)menus
{
    if (!_menus) {
        _menus = [[NSMutableArray alloc] initWithCapacity:1];
    }
    return _menus;
}

- (void)valueChang:(UISegmentedControl *)segmentedControl
{
    if (segmentedControl.selectedSegmentIndex == 0) {
        [self.menus removeObject:[self.menus firstObject]];
    }else{
        XHMenu *menu = [[XHMenu alloc] init];
        menu.title = @"添加";
        menu.titleNormalColor = [UIColor colorWithWhite:0.141 alpha:1.000];
        menu.titleFont = [UIFont boldSystemFontOfSize:16];
        [self.menus addObject:menu];
        [menu release];
    }
    self.scrollMenus.menus = self.menus;
    [self.scrollMenus reloadData];
    
  
}




- (void)viewDidLoad {
    [super viewDidLoad];

    
    
    _scrollMenus = [[XHScrollMenu alloc] initWithFrame:CGRectMake(0, 10, CGRectGetWidth(self.view.bounds), 36)];
    _scrollMenus.backgroundColor = [UIColor colorWithWhite:0.902 alpha:1.000];
    _scrollMenus.delegate = self;
    
    [self.view addSubview:self.scrollMenus];
    
    
    NSArray *chanelArray = @[@"车系收藏", @"车型收藏", @"文章收藏"];
    for (int i = 0; i < chanelArray.count; i++) {
        XHMenu *menu = [[XHMenu alloc] init];
        menu.title = chanelArray[i];
        menu.titleNormalColor = [UIColor colorWithWhite:0.141 alpha:1.000];
        menu.titleFont = [UIFont boldSystemFontOfSize:16];
        [self.menus addObject:menu];
        
//~~~~~~tableView2 是哪个页面
//        UITableView *tableView2 = [[[UITableView alloc] initWithFrame:CGRectMake(i * CGRectGetWidth(_scrollMenus.bounds), 180./667 * self.view.frame.size.height, CGRectGetWidth(_scrollMenus.bounds), CGRectGetHeight(_scrollMenus.bounds))] autorelease];
//        
//        tableView2.backgroundColor = [UIColor yellowColor];
//        tableView2.delegate = self;
//        tableView2.dataSource = self;
        
        
        //根据标题记载页面
        if ([menu.title isEqualToString:@"车系收藏"]) {
            
            SystemTableViewController *systemTVC = [[SystemTableViewController new] autorelease];
            systemTVC.tableView.frame = CGRectMake(i * CGRectGetWidth(_scrollMenus.bounds), 180./667 * self.view.frame.size.height, CGRectGetWidth(_scrollMenus.bounds), CGRectGetHeight(_scrollMenus.bounds));
            [self.view addSubview:systemTVC.tableView];
            
            
        }else if ([menu.title isEqualToString:@"车型收藏"]){
            
            ModelTableViewController *modelTVC = [[ModelTableViewController new] autorelease];
            modelTVC.tableView.frame = CGRectMake(i * CGRectGetWidth(_scrollMenus.bounds), 180./667 * self.view.frame.size.height, CGRectGetWidth(_scrollMenus.bounds), CGRectGetHeight(_scrollMenus.bounds));
            [self.view addSubview:modelTVC.tableView];
            
            
        }
      
    }
 
}




#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 0;
}


//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    
//        static NSString *idefierCell = @"mycell";
//    
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:idefierCell];
//    if (cell == nil) {
//        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:idefierCell];
//    }
//    
//    return cell;
//}

- (void)scrollMenuDidSelected:(XHScrollMenu *)scrollMenu menuIndex:(NSUInteger)selectIndex
{
    NSLog(@"selectIntex:%ld", (unsigned long)selectIndex)
    ;
    self.shouldObserving = NO;
    [self menuSelectedIndex:selectIndex];
    
}

- (void)scrollMenuDidManagerSelected:(XHScrollMenu *)scrollMenu
{
    NSLog(@"scrollMenuDidMangerSelected");
}
- (void) menuSelectedIndex:(NSUInteger)index
{
    
    
    
    
    
    
    
}



-(void)dealloc
{
   
 
    [_scrollMenus release];
    [_menus release];
    
    [super dealloc];
}

@end
